package com.primeton.esper.main.inc;

import com.espertech.esper.client.EPServiceProvider;
import com.espertech.esper.client.EPServiceProviderManager;
import com.espertech.esper.client.EPStatement;
import com.espertech.esper.client.EventBean;
import com.espertech.esper.client.UpdateListener;
import com.primeton.esper.config.ConfigurationFactory;
import com.primeton.esper.evententry.OrderEvent;

public class TestClass {

	private static EPServiceProvider	epService	= EPServiceProviderManager.getDefaultProvider(ConfigurationFactory
																									.getEsperConfiguration());

	public static void testExpr() {
		String express = "select * from OrderEvent.win:expr(oldest_timestamp > newest_timestamp - 2000)";
		EPStatement statement = epService.getEPAdministrator().createEPL(express, "test");
		System.out.println(statement.getName() + "----Name");
		// statement.s
		statement.addListener(new UpdateListener() {

			@Override
			public void update(EventBean[] newEvents, EventBean[] oldEvents) {
				// TODO Auto-generated method stub
				System.out.println(newEvents[0].getUnderlying());
				System.out.println("-------------------------");
				// SafeIterator<EventBean> si =
				// epService.getEPAdministrator().getStatement("test").safeIterator();
				// while (si.hasNext()) {
				// System.out.println(si.next());
				// }
			}
		});

		new Thread() {

			@Override
			public void run() {
				while (true) {
					for (int i = 0; i < 10; i++) {
						System.out.println("test" + (i + 1));
						OrderEvent o1 = new OrderEvent("songfei", 26);
						epService.getEPRuntime().sendEvent(o1);
						try {
							sleep(600);
						} catch (InterruptedException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
							System.out.println("something wrong!!");
						}
					}
					break;
				}
			}

		}.start();
	}
}
